from multiprocessing import Process
import os
import time
def sub_p1(name):
    print(f"子进程pid是：{os.getpid()},父进程的pid是：{os.getppid()}", name)
    time.sleep(1)
def sub_p2(name):
    print(f"子进程pid是：{os.getpid()},父进程的pid是：{os.getppid()}", name)
    time.sleep(1)
if __name__ == '__main__':
    print("主进程开始执行")
    for i in range(5):
        # 创建5个子进程
        p1 = Process(target=sub_p1, args=("第1个",))
        p2 = Process(target=sub_p1, args=("第2个",))
        # 启动子进程
        p1.start()
        p2.start()
        print(p1.name, "pid是", p1.pid, "是否执行完毕", p1.is_alive())
        print(p2.name, "pid是", p1.pid, "是否执行完毕", p2.is_alive())
        # 启动中的进程
        # lst.append(p)
        # 主程序要等待p1的结束
        p1.join()
        p2.join()
    print("主进程执行结束")
